home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / tool / artemis1 / src / goshi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  5.3 KB  |  224 lines

  1. /*
  2.     ARTemis (Graphic Editor for FM-TOWNS)
  3.     (c) MATSUUCHI Ryosuke 1992
  4.  
  5.     goshi.c
  6.  
  7.     摩筆のシミュレート
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <egb.h>
  12. #include <stdlib.h>
  13. #include <msdos.cf>
  14. #include <fnt.h>
  15. #include <ctype.h>
  16.  
  17. #include "ge.h"
  18. #include "dispman.h"
  19. #include "imageman.h"
  20.  
  21.  
  22. typedef struct {
  23.     char b,r,g;
  24.     char dmy;
  25. } pencol_t;
  26.  
  27. #define    subst_pencol(obj, r,g,b)    \
  28.     *(int*)&(obj) = ((int)(g) << 16) | ((int)(r) << 8) | (int)(b)
  29.  
  30. // static int pencol_r[16][16], pencol_g[16][16], pencol_b[16][16];
  31. static pencol_t penc[32][32];
  32.  
  33. #define    XL    32
  34. #define    YL    32
  35. #define    CX    15
  36. #define    CY    15
  37.  
  38. void get_pencol(int x, int y, pen_t *pen)
  39. /*
  40.     ペン先に色をコピーする
  41. */
  42. {
  43.     int c;
  44.     if (mode != MODE32K)
  45.         return;
  46.     if (pen_isdottype(pen))
  47.         c = EIMpoint(x,y), subst_pencol(penc[CY][CX], getR(c), getG(c), getB(c));
  48.     else
  49.     {
  50.         int maxx,maxy;
  51.         maxx = EIMgetxsize();
  52.         maxy = EIMgetysize();
  53.         void get_pencol_hline(int x0,int y0,int dx,int xlen,int dy,
  54.                               short *graymap)
  55.         {
  56.             int i; short *ep;
  57.             ep = (short*)EIMadrs(x0+dx,_lim(y0+dy,0,maxy));
  58.             for (i=0; i<xlen; i++)
  59.             {
  60.                 int ix = _lim(x0+dx+i,0,maxx) - (x0+dx);
  61.                 c = *(ep + ix);
  62.                 subst_pencol(penc[CY+dy][CX+dx+i],getR(c),getG(c),getB(c));
  63.             }
  64.         }
  65.         pen_fill(pen, get_pencol_hline, x,y, NO);
  66.     }
  67. #if 0
  68.         x1 = _max(x - 7 + 0,  0) - (x - 7);
  69.         y1 = _max(y - 7 + 0,  0) - (y - 7);
  70.         x2 = _min(x - 7 + 15,  maxx) - (x - 7);
  71.         y2 = _min(y - 7 + 15,  maxy) - (y - 7);
  72.         //
  73.         // 16×16の領域のうち、画面の上にはみ出した部分の処理
  74.         if (0 < y1)
  75.         {
  76.             for (j=0; j<=15; j++)
  77.             {
  78.                 int tx = (j < x1 ? 0 : x2 < j ? maxx : x - 7 + j);
  79.                 c = EIMpoint(tx, 0);
  80.                 for (i=0; i<y1; i++)
  81.                     if (pen->pat[i*16+j] > 0)
  82.                         subst_pencol(penc[i][j], getR(c), getG(c), getB(c));
  83.             }
  84.         }
  85.         for (i=y1; i<=y2; i++)
  86.         {
  87.             int pi;
  88.             //
  89.             // 16×16の領域で、画面の上端・下端の間にある部分のうち、
  90.             // 画面の左にはみ出した部分の処理
  91.             if (0 < x1)
  92.             {
  93.                 c = EIMpoint(0, y-7+i);
  94.                 for (j=0; j<x1; j++)
  95.                     if (pen->pat[i*16+j] > 0)
  96.                         subst_pencol(penc[i][j], getR(c), getG(c), getB(c));
  97.             }
  98.             //
  99.             // 16×16の領域で、完全に画面内にある部分の処理
  100.             short *ep;
  101.             ep = (short*)EIMadrs(x-7+x1,y-7+i);
  102.             pi = i*16+x1;
  103.             for (j=x1; j<=x2; j++,ep++,pi++)
  104.                 if (pen->pat[pi] > 0)
  105.                     c = *ep, subst_pencol(penc[i][j], getR(c), getG(c), getB(c));
  106.             //
  107.             // 16×16の領域で、画面の上端・下端の間にある部分のうち、
  108.             // 画面の右にはみ出した部分の処理
  109.             if (x2 < 15)
  110.             {
  111.                 c = EIMpoint(maxx, y-7+i);
  112.                 for (j=x2+1; j<=15; j++)
  113.                     if (pen->pat[i*16+j])
  114.                         subst_pencol(penc[i][j], getR(c), getG(c), getB(c));
  115.             }
  116.         }
  117.         //
  118.         // 16×16の領域のうち、画面の下にはみ出した部分の処理
  119.         if (y2 < 15)
  120.         {
  121.             for (j=0; j<=15; j++)
  122.             {
  123.                 int tx = (j < x1 ? 0 : x2 < j ? maxx : x - 7 + j);
  124.                 c = EIMpoint(tx, maxy);
  125.                 for (i=y2+1; i<=15; i++)
  126.                     if (pen->pat[i*16+j] > 0)
  127.                         subst_pencol(penc[i][j], getR(c), getG(c), getB(c));
  128.             }
  129.         }
  130.     }
  131. #endif
  132. }
  133.  
  134.  
  135.  
  136. void put_pencol(int x, int y, pen_t *pen)
  137. /*
  138.     ペン先の色と画面の色の間で平均をとる
  139. */
  140. {
  141.     int para = goshi_para;
  142.     pencol_t *pc;
  143.     if (mode != MODE32K)
  144.         return;
  145.     int i,j;
  146.     if (pen_isdottype(pen))
  147.     {
  148.         int c,cr,cg,cb,r,g,b;
  149.         c = EIMpoint(x,y);
  150.         cr = getR(c), cg = getG(c), cb = getB(c);
  151.         pc = &penc[CY][CX];
  152.         r = (cr*(256-para) + pc->r*para + 128) >>8;
  153.         g = (cg*(256-para) + pc->g*para + 128) >>8;
  154.         b = (cb*(256-para) + pc->b*para + 128) >>8;
  155.         pc->r -= (pc->r - r);
  156.         pc->g -= (pc->g - g);
  157.         pc->b -= (pc->b - b);
  158.         EIMpset(x,y, r*32+g*1024+b, DrawNORMAL);
  159.     }
  160.     else
  161.     {
  162.         void put_pencol_hline(int x0,int y0,int dx,int xlen,int dy,
  163.                               short *graymap)
  164.         {
  165.             int i; short *ep,*ep0;
  166.             ep0 = ep = (short*)EIMadrs(x0+dx,y0+dy);
  167.             for (i=0; i<xlen; i++,ep++)
  168.             {
  169.                 int c = *ep, cr = getR(c), cg = getG(c), cb = getB(c);
  170.                 pc = &penc[CY+dy][CX+dx+i];
  171.                 int r,g,b;
  172.                 r = (cr*(256-para)+pc->r*para+(my_rand() & 255)) >>8;
  173.                 g = (cg*(256-para)+pc->g*para+(my_rand() & 255)) >>8;
  174.                 b = (cb*(256-para)+pc->b*para+(my_rand() & 255)) >>8;
  175.                 pc->r -= (pc->r - r);
  176.                 pc->g -= (pc->g - g);
  177.                 pc->b -= (pc->b - b);
  178.                 *ep = r*32+g*1024+b;
  179.             }
  180.             DMimage_hline_map(x0+dx,x0+dx+xlen-1,y0+dy,(char*)ep0);
  181.         }
  182.         pen_fill(pen, put_pencol_hline, x,y, YES);
  183.     }
  184. #if 0
  185.         int x1,y1,x2,y2,maxx,maxy;
  186.         maxx = EIMgetxsize()-1;
  187.         maxy = EIMgetysize()-1;
  188.         x1 = _max(x - 7 +  0,     0);
  189.         y1 = _max(y - 7 +  0,     0);
  190.         x2 = _min(x - 7 + 15,  maxx);
  191.         y2 = _min(y - 7 + 15,  maxy);
  192.         for (i=y1; i<=y2; i++)
  193.         {
  194.             short *ep0 = (short *)EIMadrs(x1,i);
  195.             void hline(int _x1, int _x2, int _y)
  196.             {
  197.                 int pi = (_y-(y-7)) * 16 + (_x1-(x-7));
  198.                 short *ep = ep0 + _x1 - x1;
  199.                 for (int ii=_x1; ii<=_x2; ii++,ep++,pi++)
  200.                 {
  201.                     if (pen->pat[pi] <= 0)
  202.                         continue;
  203.                     int c = *ep, cr = getR(c), cg = getG(c), cb = getB(c);
  204.                     pc = &penc[_y-(y-7)][ii-(x-7)];
  205.                     int r,g,b;
  206.                     r = (cr*(256-para)+pc->r*para+(my_rand() & 255)) >>8;
  207.                     g = (cg*(256-para)+pc->g*para+(my_rand() & 255)) >>8;
  208.                     b = (cb*(256-para)+pc->b*para+(my_rand() & 255)) >>8;
  209.                     pc->r -= (pc->r - r);
  210.                     pc->g -= (pc->g - g);
  211.                     pc->b -= (pc->b - b);
  212.                     *ep = r*32+g*1024+b;
  213.                 }
  214.             }
  215.             hline_func(x1,x2,i, hline);
  216.             DMimage_hline_map(x1,x2,i,(char*)ep0);
  217.         }
  218.     }
  219. #endif
  220. }
  221.  
  222.  
  223. /* end of goshi.c */
  224.